/*
 * @Author: 烟浮
 * @Date: 2023-03-22 10:21:49
 * @LastEditTime: 2023-03-22 12:12:13
 * @LastEditors: 锦墨涵秋 275740441@qq.com
 * @FilePath: /ViteSsoIndex/ViteSsoIndex/vite.config.ts
 */
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
// element-plus 自动按需导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// 代码压缩
import viteCompression from 'vite-plugin-compression'
// 图片压缩
import viteImagemin from 'vite-plugin-imagemin'
// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    }),
    viteCompression({
      //gzip压缩
      verbose: true,
      disable: false,
      threshold: 10240,
      algorithm: 'gzip',
      ext: '.gz'
    }),
    viteImagemin({
      gifsicle: {
        optimizationLevel: 7,
        interlaced: false
      },
      optipng: {
        optimizationLevel: 7
      },
      mozjpeg: {
        quality: 50
      },
      pngquant: {
        quality: [0.8, 0.9],
        speed: 4
      },
      svgo: {
        plugins: [
          {
            name: 'removeViewBox'
          },
          {
            name: 'removeEmptyAttrs',
            active: false
          }
        ]
      }
    })
  ],
  build: {
    sourcemap: true,
    // brotliSize: false, // 不统计
    outDir: 'dist', // 指定输出路径，要和库的包区分开
    assetsDir: 'static/img/', //
    target: 'esnext',
    minify: 'esbuild', // 指定生成静态资源的存放路径
    rollupOptions: {
      output: {
        chunkFileNames: 'static/js/[name]-[hash].js',
        entryFileNames: 'static/js/[name]-[hash].js',
        assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
      }
    }
  },
  server: {
    port: 3000
    // host: '0.0.0.0',
    // proxy: {
    //   '/api': {
    //     // target: 'http://10.1.11.140/api/',
    //     changeOrigin: true,
    //     rewrite: (p) => p.replace(/^\/api/, '')
    //   }
    // }
  }
})
